package com.fling.hero.state;

import com.badlogic.gdx.math.Vector2;
import com.fling.entity.CollisionEntity;
import com.fling.objects.Hero;
import com.fling.observer.Event;

public class ClimbingState extends HeroState {

	private Vector2 vel;
	public static float CLIMBING_VEL = 0;

	public ClimbingState(Hero h) {
		super(h);
		type = STATE_TYPE.CLIMB_STATE;
	}

	@Override
	public void update(float delta) {
		hero.getBody().setLinearVelocity(vel);

	}

	@Override
	public void newAction(INPUT input) {
		System.out.println(input);
		switch (input) {
		case CLIMB:
			break;
		// block cant jump up or down so revert to falling
		case JUMP_UP:
		case JUMP_DOWN:
		case FALL:
			hero.changeState(new FallingState(hero));
			exit();
			break;

		case JUMP_RIGHT:
			if (!hero.isRightSide()) {
				hero.changeState(new FirstJumpState(hero, input));
				exit();
			} else {
				hero.changeState(new FallingState(hero));
				exit();
			}
			break;
		case JUMP_LEFT:
			if (hero.isRightSide()) {
				hero.changeState(new FirstJumpState(hero, input));
				exit();
			} else {
				hero.changeState(new FallingState(hero));
				exit();
			}
			break;
		default:
			break;
		}
	}

	@Override
	public void enter() {
		vel = new Vector2(0, CLIMBING_VEL);
		hero.getSubject().notify(hero, Event.EVENT_CLIMB);
		hero.setSprite(hero.getClimbSprite());
		hero.setFlipX(hero.isRightSide());
	}

	@Override
	public void exit() {
	}

	@Override
	public void collide(CollisionEntity otherBody) {
		if (otherBody.getType().equals(TYPE.WALL)) {
			//nothing
		} else if (otherBody.getType().equals(TYPE.BLOCK)) {
			hero.die();
		}

	}
}
